package com.tedu.web;

import com.tedu.dao.ClockMapper;
import com.tedu.pojo.Clock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

/**
 * 疫情打卡
 */
@Controller
public class ClockInController {

    @Autowired
    ClockMapper mapper;

    /**
     * 显示打卡页面
     * @return
     */
    @RequestMapping("/clockIn")
    public String clockIn(){
    return "clock";
    }

    /**
     * 添加一天打开记录
     * @return
     */
    @RequestMapping("/addClock")
    public String addClock(Clock clock){
//        获取最新时间
        Date date = new Date();
        clock.setCreateTime(date);
        System.out.println(clock);
        mapper.addClock(clock);

        return "clockList";

    }

    /**
     * 显示打卡记录
     */
    @RequestMapping("/clockList")
    public String clockList(Model model){
        // 调用dao获取全部数据
        List<Clock> data = mapper.getAll();
        model.addAttribute("list",data);
        System.out.println(data);
        return "clockList";
    }

}
